﻿using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using NHibernate;
using Shape.Mvp.Ioc;
using SimpleTasks.Persistence;
using SimpleTasks.Persistence.Hibernate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleTasks.IoC.Installers
{
   public class UnitOfWorkInstaller : IWindsorInstaller
   {
      public void Install(IWindsorContainer container, IConfigurationStore store)
      {
         container.Register(
            Component.For<ISessionFactory>()
           .UsingFactoryMethod(() => HibernateHelper.BuildSessionFactory())
           .LifestyleSingleton());

         container.Register(
            Component.For<HibernateUnitOfWork, IUnitOfWork>()
           .ImplementedBy<HibernateUnitOfWork>()
           .LifestyleScoped());
      }
   }
}
